import {defineStore} from "pinia";
export const useDoubanStore = defineStore('douban', {
    state() {
        return {
            doubanData: [], // 热门
            doubanDataSciFi: [], // 科幻
            doubanDataTerrified: [], // 惊悚
            doubanScenario: [], // 剧情,
            doubanComedy: [], // 喜剧,
            doubanAction: [], // 动作
            doubanLove: [], // 爱情
            doubanAnimation: [], // 动画
            doubanMystery: [], // 悬疑
            doubanTerror: [], // 恐怖
            doubanDocumentary: [], // 纪录片
            doubanShort: [], // 短片
            doubanColor: [], // 情色
            doubanMusic: [], // 音乐
            doubanDance: [], // 舞蹈
            doubanFamily: [], // 家庭
            doubanChild: [], // 儿童
            doubanLife: [], // 传记
            doubanHistory: [], // 历史
            doubanWar: [], // 战争
            doubanOffence: [], // 犯罪
            doubanWest: [], // 西部
            doubanFunhouse: [], // 奇幻
            doubanRisk: [], // 冒险
            doubanDisaster: [], // 灾难
            doubanWX: [], // 武侠
            doubanCostume: [], // 古装
            doubanSport: [], // 运动
            doubanBlack: [], // 黑色电影
            doubanTop250: [], // 电影top250
        }
    },
    actions: {
        async getDoubanData() {
            let res:any = await $fetch('/api/douban/new')
            if (res.code === 200) {
                this.doubanData = res.data
            }
        },
        async getDoubanDataSciFi() {
            let res: any = await $fetch('/api/douban/scifi')
            if (res.code == 200) {
                this.doubanDataSciFi = res.data
            }
        },
        async getAnimation() {
            let res: any = await $fetch('/api/douban/animation')
            if (res.code == 200) {
                this.doubanAnimation = res.data
            }
        },
        async getComedy() {
            let res: any = await $fetch('/api/douban/comedy')
            if (res.code == 200) {
                this.doubanComedy = res.data
            }
        },
        async getDocumentary() {
            let res: any = await $fetch('/api/douban/documentary')
            if (res.code == 200) {
                this.doubanDocumentary = res.data
            }
        },
        async getHistory() {
            let res: any = await $fetch('/api/douban/history')
            if (res.code == 200) {
                this.doubanHistory = res.data
            }
        },
        async getLove() {
            let res: any = await $fetch('/api/douban/love')
            if (res.code == 200) {
                this.doubanLove = res.data
            }
        },
        async getTerrified() {
            let res: any = await $fetch('/api/douban/terrified')
            if (res.code == 200) {
                this.doubanDataTerrified = res.data
            }
        },
        async getWar() {
            let res: any = await $fetch('/api/douban/war')
            if (res.code == 200) {
                this.doubanWar= res.data
            }
        },
        async getTop250() {
            let res: any = await $fetch('/api/douban/top250')
            if (res.code == 200) {
                this.doubanTop250 = res.data
            }
        }
    },
    persist: {
        storage: persistedState.localStorage
    },
})